package com.situ.springboot.collection;

import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.FileFilter;
import java.util.*;

public class CollectionDemo {

    @Test
    public void test() {
        Set<Student> set = new HashSet<>();
        Student student1 = new Student(1, "zhangsan", 22);
        Student student2 = new Student(2, "lisi", 22);
        Student student3 = new Student(3, "wangwu", 22);
        Student student4 = new Student(1, "zhangsan", 22);
        set.add(student1);
        set.add(student2);
        set.add(student3);
        set.add(student4);
        for (Student student : set) {
            System.out.println(student);
        }
    }

    @Test
    public void test2() {
        TreeSet<Student> treeSet = new TreeSet<>();
        treeSet.add(new Student(1, "张三", 23));
        treeSet.add(new Student(2, "李四", 13));
        treeSet.add(new Student(3, "周七", 13));
        treeSet.add(new Student(4, "王五", 43));
        treeSet.add(new Student(5, "赵六", 33));

        System.out.println(treeSet);
    }

    @Test
    public void test3() {
        File currentDirectory = new File("D:\\Java Project\\STProjects\\Hospital");
        //File[] files = currentDirectory.listFiles();
        File[] files = currentDirectory.listFiles(new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                return !pathname.getName().startsWith(".");
            }
        });

        Collections.sort(Arrays.asList(files), new Comparator<File>() {

            @Override
            public int compare(File file1, File file2) {
                if (file1.isDirectory() && file2.isFile()) {
                    return 1;
                } else if (file1.isFile() && file2.isDirectory()) {
                    return -1;
                } else {
                    return file1.getName().compareTo(file2.getName());
                }
            }
        });

        for (File file : files) {
            System.out.println(file);
        }
    }
}
